<template>
  <section class="component repair-case-distrubute">
    <el-form ref="form" label-width="90px">
      <el-form-item>
        <span style="color:#20a0ff;">当前已选择{{selectionList.length}}个案件，案件总金额￥{{overdueAmount | toThousands}}</span>
      </el-form-item>
      <el-form-item>
        <el-radio-group v-model="distributeType">
          <el-radio label="TEL">分配到电催案件池</el-radio>
          <el-radio label="VISIT">分配到外访案件池</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div class="operate-buttons">
      <el-button @click="emitClose">取消</el-button>
      <el-button v-if="!robberyCaseTrue" @click="submit">确定</el-button>
      <el-button v-else @click="submitTwo">确定</el-button>
    </div>
  </section>
</template>

<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Dependencies } from '~/core/decorator';
import { Emit, Prop } from 'vue-property-decorator';
import { RepairCasesService } from '~/services/domain-service/repair-cases.service';
import { RobCaseService } from '~/services/domain-service/rob-case.service.ts';

@Component({
  components: {},
})
export default class RepairCaseDistrubute extends Vue {
  @Prop()
  private selectionList: any;
  // 判断是不是抢案案件过来
  @Prop()
  private robberyCaseTrue:any
  @Dependencies(RobCaseService) private robCaseService: RobCaseService;
  @Dependencies(RepairCasesService) private repairCasesService: RepairCasesService;

  private distributeType: string = ""


  @Emit('success')
  private emitSuccess() {
    this.$message.success('分配成功');
    this.emitClose()
  }
  @Emit('close')
  private emitClose() {
    this.distributeType = ""
  }

  private get overdueAmount() {
    const sum = this.selectionList
      .map((v) => v.overdueAmount)
      .reduce((a, b) => a + b, 0)
      .toFixed(2);
    return sum;
  }
  /**
   * 首次打开弹窗执行
   */
   private update(){
     this.distributeType = "TEL"
   }

  /**
   * 确定
   */
  private submit() {
    const caseId: any = this.selectionList.map((v) => v.id);
    const paramData: any = {
      caseIds: caseId,
      distributeType: this.distributeType,
    };
    this.repairCasesService.distributeRepairCases(paramData).subscribe(this.emitSuccess);
  }
  /**
   * 抢案 -- 确定
   */
   private submitTwo() {
    const caseId: any = this.selectionList.map((v) => v.id);
    const paramData: any = {
      caseIds: caseId,
      distributeType: this.distributeType,
    };
    this.robCaseService.distributeRobCase(paramData).subscribe(this.emitSuccess);
  }

}
</script>

<style lang="less" scoped>
</style>
